home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / NetFractal™ / Fractal 8 source / OutPoint.cpp < prev    next >
Encoding:
Text File  |  1995-06-24  |  1.5 KB  |  91 lines  |  [TEXT/MPCC]

  1. //    OutPoint.cpp
  2.  
  3.  
  4. #include "OutPoint.h"
  5.  
  6. #define TIMEOUT 2000
  7.  
  8.  
  9. OutPoint::OutPoint(
  10.     const char *protocol,
  11.     const char *address,
  12.     short port)
  13. {
  14.     OSStatus err = Open(protocol);
  15.  
  16.     if (err)
  17.         throw err;
  18.  
  19.     err = Bind(port);
  20.     if (err)
  21.         throw err;
  22.  
  23.  
  24.     char bfr [256];
  25.     TLookupRequest req = { { 0, strlen(address), (UInt8*) address},
  26.                             { 0, 0, 0}, 1, 4000 };
  27.     TLookupReply rep = { { 256, 0, (UInt8*) bfr }, 1 };
  28.  
  29. //    TLookupReply rep = { { sizeof(InetAddress), 0, (UInt8*) &fHisAddress }, 1 };
  30.  
  31.     MapperRef inet = OTOpenMapper(OTCreateConfiguration("dnr"), 0, &err);
  32.     if (err)
  33.         throw err;
  34.     err = OTLookupName(inet, &req, &rep);
  35.     if (err)
  36.         throw err;
  37.  
  38.     
  39.     fHisAddressSize = *(short*) bfr;
  40.     ::BlockMoveData(bfr+4, &fHisAddress, fHisAddressSize);
  41.     fHisAddress.inet.fPort = OUR_PORT;
  42.  
  43.  
  44.  
  45. /*
  46.     DNSAddress inAddress;
  47.     strcpy(inAddress.fName, address);
  48.     inAddress.fAddressType = kOTGenericName;
  49.     
  50.     TBind inBind = { { 0,  sizeof(short)+strlen(address)-1, (UInt8*) &inAddress }, 0};
  51.     TBind outBind = { { sizeof(InetAddress), 0, (UInt8*) &fHisAddress }, 0};
  52.  
  53.  
  54.     err = OTResolveAddress(fEndpoint, &inBind, &outBind, TIMEOUT);
  55.  
  56.     if (err)
  57.         throw err;
  58.     fHisAddressSize = outBind.addr.len;
  59. */
  60. }
  61.  
  62.  
  63. OutPoint::~OutPoint()
  64. {
  65. }
  66.  
  67.  
  68. OSErr
  69. OutPoint::SendData(
  70.     const void *data,
  71.     long size)
  72. {
  73.  
  74.     OSStatus err;
  75.     
  76.     while (1) {
  77.         TUnitData uData = {
  78.             { 0, fHisAddressSize, (UInt8*) &fHisAddress },
  79.             { 0, 0, NULL },
  80.             { 0, (size_t) size, (UInt8*) data },
  81.         };
  82.     
  83.         err = OTSndUData(fEndpoint, &uData);
  84.         if (err != kOTLookErr)
  85.             break;
  86.         OTRcvUDErr(fEndpoint, nil);
  87.     }
  88.  
  89.     return (OSErr) err;
  90. }
  91.